import { fromJS } from 'immutable'
import {INPUT_FOCUS, INPUT_BLUR, CHANGE_LIST, CHANGE_PAGE, MOUSE_ENTER, MOUSE_LEAVE} from './actionTypes';

const defaultState = fromJS({
  focused: false,
  list: [],
  mouseIn: false,
  page: 1,
  totalPage: 1
});


export default (state = defaultState, action) => {
  switch (action.type) {
    case INPUT_FOCUS:
      return state.set('focused', true);
    case  INPUT_BLUR:
      return state.set('focused', false);
    case  CHANGE_LIST:   // 设置多个值使用merge
      return state.merge({
        'list': action.data,
        'totalPage': action.total
      });
    case CHANGE_PAGE:
      return state.set('page', action.page);
    case MOUSE_ENTER:
      return state.set('mouseIn', true);
    case MOUSE_LEAVE:
      return state.set('mouseIn', false);
    default:
      return state;
  }
};